package madixin.t452;

import java.util.Arrays;
import java.util.Comparator;

class Solution {
    //贪心法
    public int findMinArrowShots(int[][] points) {
        if (points == null || points.length == 0 || points[0].length == 0) {
            return 0;
        }

        Arrays.sort(points, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[1] - o2[1];
            }
        });

        int res = 1;
        int end = points[0][1];
        for (int i = 0; i < points.length; i++) {
            if (points[i][0] > end) {
                res++;
                end = points[i][1];
            }
        }

        return res;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.findMinArrowShots(new int[][]{{10, 16}, {2, 8}, {1, 6}, {7, 12}}));
    }
}
